package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.wanho.po.Emp;
import net.wanho.mapper.EmpMapper;
import net.wanho.service.EmpService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 员工表 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-12-20
 */
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {

    @Override
    public List<Emp> selectAll() {
        return this.baseMapper.selectAll();
    }

    @Override
    public Page<Emp> findByPage(int pageNum, int pageSize, Emp emp) {
        Page<Emp> page = new Page<>(pageNum, pageSize);

        QueryWrapper<Emp> wrapper = new QueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(emp.getName()), "e.name", emp.getName());
        wrapper.eq(!ObjectUtils.isEmpty(emp.getSalary()), "salary", emp.getSalary());
        if (emp.getDept()!=null){
            wrapper.eq(!ObjectUtils.isEmpty(emp.getDept().getName()), "d.name", emp.getDept().getName());
        }

        this.baseMapper.selectByPage(page, wrapper);

        return page;
    }
}
